<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Recruit extends Model
{
    protected $table = 'recruit';//信息表
    public $timestamps = false;
    protected $guarded = [
       ];
    //招聘信息
    public function recruit($search = [], $page = 1, $length = 20){
        $recruitList = array();
        $recruitList['pageData'] = array();


        $sql = \DB::table($this->table)
            ->whereNull('deleted_at');

        if(isset($search['name'])){
            $sql->where('name', 'like', "%".$search['name']."%");
        }

        $recruitList['pageData']['count']     = $sql->count();
        $recruitList['pageData']['lastPage']  = ceil($recruitList['pageData']['count'] / $length);

        $recruitList['list'] = $sql->orderBy('sort', 'desc')
            ->skip(($page-1) * $length)->take($length)
            ->get();

        return $recruitList;
    }

    //删除
    public function Del($data,$id){
        return \DB::table($this->table)->where('id',$id)->update($data);
    }

    public function saveData($data){
        return \DB::table($this->table)->insert($data);
    }
}